//
//  MyHelpCentre.m
//  ZITHER
//
//  Created by weixin on 2018/11/21.
//  Copyright © 2018 weixn. All rights reserved.
//

#import "MyHelpCentre.h"
#import "MyHelpCentreWebVC.h"

@interface MyHelpCentre ()

@property (nonatomic,strong)BaseImageV *image;//app 图片名称

@end

@implementation MyHelpCentre

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setNav];
    [self setUI];
   
}

-(void)setNav{
    [self.baseNavigationView setHiddenNav:NO VC:self];
    self.baseNavigationView.isShowShadow = YES;
    self.baseNavigationView.bottomLineView.hidden = YES;
    [self.baseNavigationView NavigationBarStyle:1];
    
    [self.baseNavigationView setIsShowShadow:NO];
    self.baseNavigationView.navViewStyle.rightBtn.hidden = NO;
    [self.baseNavigationView.navViewStyle.rightBtn setImage:[UIImage imageNamed:@"客服"] forState:UIControlStateNormal];
    self.baseNavigationView.navViewStyle.backgroundColor = [UIColor whiteColor];
    self.baseNavigationView.navViewStyle.rightBtn.frame = CGRectMake(kScreenW-50, 0, 48, 40);
    self.baseNavigationView.navViewStyle.rightBtn.centerY = self.baseNavigationView.navViewStyle.centerY+centerYH;

    @weakify(self);
    [[self.baseNavigationView.navViewStyle.rightBtn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
        @strongify(self);
        
        NSMutableString *str=[[NSMutableString alloc]initWithFormat:@"电话号码:0755-82523823"];
        
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:str preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
        }];
        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
            NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"tel://0755-82523823"]];
            [[UIApplication sharedApplication] openURL:url];
        }];
        // Add the actions.
        
        [alertController addAction:cancelAction];
        
        [alertController addAction:otherAction];
        
        [self.navigationController presentViewController:alertController animated:YES completion:nil];
    }];

}

-(void)setUI{
    
    [self.view addSubview:self.image];
    [self.image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(NaviHeight+30);
        make.centerX.equalTo(self.view).offset(0);
        make.height.mas_equalTo(40);
        make.width.mas_equalTo(100);
    }];
    
    NSArray *arrTitle = @[@"入门须知",@"社区达人",@"了解更多"];
    NSArray *arrTitleSub = @[@"免责条款",@"使用指南",@"FAQ"];
    NSArray *arrImage = @[@"入门须知",@"社区达人",@"了解更多"];

    
    NSString *urlString = [NSString stringWithFormat:@"%@/#/faq/clause?name=%@",RootUrlWeb,RootProjectName];
    
    NSString *encodedString = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,(CFStringRef)urlString,(CFStringRef)@"!$&'()*+,-./:;=?@_~%#[]",NULL,kCFStringEncodingUTF8));
    
    NSString * urlstr1 = encodedString;

//    NSString * urlstr1 = [NSString stringWithFormat:@"%@/#/faq/clause",RootUrlWeb];
    NSString * urlstr2 = [NSString stringWithFormat:@"%@/#/faq/rule",RootUrlWeb];
    NSString * urlstr3 = [NSString stringWithFormat:@"%@/#/faq",RootUrlWeb];

    NSArray *url = @[urlstr1,urlstr2,urlstr3];

    NSArray *title = @[@"免责条款",@"社区规则",@"FAQ"];
    
    CGFloat height = 200;
    for (int i = 0 ; i<3; i++) {
        BaseImageV *image = [[BaseImageV alloc]initializeFrame:CGRectMake(15, height+i*115, kScreenW-30, 105) contentMode:2];
        [image setCornerRadiusWithRadius:10 isMasks:YES];
        image.tag = 100+i;
        if ([Main_Token_Model_MANAGER.isToken isEqualToString:@"1"]){
            image.backgroundColor = RandomColor;
        }else{
            image.image = [UIImage imageNamed:arrImage[i]];
        }

        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
        [[tap rac_gestureSignal] subscribeNext:^(__kindof UIGestureRecognizer * _Nullable x) {
            MyHelpCentreWebVC *vc = [[MyHelpCentreWebVC alloc]init];
            switch (image.tag) {
                case 100:
                    vc.url = url[i];
                    vc.title1 = title[i];
                    break;
                case 101:
                    vc.url = url[i];
                    vc.title1 = title[i];
                    break;
                case 102:
                    vc.url = url[i];
                    vc.title1 = title[i];
                    break;
                default:
                    break;
            }
            [self.navigationController pushViewController:vc animated:YES];
        }];
        image.userInteractionEnabled = YES;
        [image addGestureRecognizer:tap];
        [self.view addSubview:image];
        
        
        BaseLab *lab = [[BaseLab alloc]initializeFrame:CGRectMake(20, 30, 100, 20) text:arrTitle[i] font:16 textColor:[UIColor whiteColor] isBold:NO numberOfLines:0];
        lab.font = [UIFont fontWithName:@"PingFangSC-Semibold" size:16];
        lab.backgroundColor = [UIColor clearColor];
        [image addSubview:lab];
        
        
        BaseLab *lab2 = [[BaseLab alloc]initializeFrame:CGRectMake(20, 115-50, 100, 20)  text:arrTitleSub[i] font:16 textColor:[UIColor whiteColor] isBold:NO numberOfLines:0];
        lab2.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:12];
        lab2.backgroundColor = [UIColor clearColor];
        [image addSubview:lab2];
        
        
    }
    NSLog(@"");
}


-(BaseImageV *)image{
    if (!_image) {
        _image = [[BaseImageV alloc]initializeFrame:CGRectMake(0, 0, 53, 20) contentMode:1];
        _image.image = [UIImage imageNamed:@"文字logo"];
    }
    return _image;
}

@end
